﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HAVTKPack
{
   public  class IsEffectiveScalarSignChanged
    {
        /// <summary>
        /// 判断网格Grid单元的有效性标记数组是否发生变化
        /// </summary>
        /// <param name="oldSign"></param>
        /// <param name="newSign"></param>
        /// <returns></returns>
        public static bool IsCellSignChanged(List<int[,]> oldSign, List<int[,]> newSign)
        {
            if ((oldSign == null && newSign != null) || (oldSign != null && newSign == null))
            {
                return true;
            }
            if (oldSign == null && newSign == null)
            {
                return false;
            }
            if (oldSign.Count != newSign.Count)
            {
                return true;
            }
            if (oldSign.Count == 0 && newSign.Count == 0)
            {
                return false;
            }
            //两者 count 相等  并且不为0
            for (int i = 0; i < oldSign.Count; i++)
            {
                if ((oldSign[i] == null && newSign[i] != null) || (oldSign[i] != null && newSign[i] == null))
                {
                    return true;
                }
                else if (oldSign[i] != null && newSign[i] != null)
                {

                    if ((oldSign[i].GetLength(0) != newSign[i].GetLength(0)) || (oldSign[i].GetLength(1) != newSign[i].GetLength(1)))
                    {
                        return true;
                    }
                    else
                    {
                        for (int rows = 0; rows < oldSign[i].GetLength(0); rows++)
                        {
                            for (int cols = 0; cols < oldSign[i].GetLength(1); cols++)
                            {
                                if (oldSign[i][rows, cols] != newSign[i][rows, cols])
                                {
                                    return true;
                                }
                            }

                        }
                    }


                }
            }


            return false;
        }


       /// <summary>
        /// 判断层Layer单元的有效性标记数组是否发生变化
       /// </summary>
       /// <param name="oldSign"></param>
       /// <param name="newSign"></param>
       /// <returns></returns>

        public static bool IsLayerCellSignChanged(int[,] oldSign, int[,] newSign)
        {
            if ((oldSign == null && newSign != null) || (oldSign != null && newSign == null))
            {
                return true;
            }
            if (oldSign == null && newSign == null)
            {
                return false;
            }

            if (oldSign .GetLength (0)!=newSign .GetLength (0) || oldSign .GetLength (1)!=newSign .GetLength (1))
            {
                return true;
            }

            for (int i = 0; i < oldSign .GetLength (0); i++)
            {
                for (int j = 0; j < oldSign .GetLength (1); j++)
                {
                    if (oldSign [i,j ]!=newSign [i,j])
                    {
                        return true;
                    }

                }
                
            }

            return false;
        
        }



    }


}
